<template>
  <div class="tab-control">
    <div class="tab-control-item" :class="{active:index === currentIndex}" v-for="(item,index) of titles" :key="index"
      @click="tabChange(index)">
      <span>{{item}}</span>
    </div>
  </div>
</template>

<script>
  export default {
    data() {
      return {
        currentIndex: 0
      }
    },
    props: {
      titles: {
        type: Array,
        default () {
          return []
        }
      }
    },
    methods: {
      tabChange(index) {
        if(this.currentIndex == index){
          return;
        }
        this.currentIndex = index;
        this.$emit('tabClick',index);
      }
    }
  }
</script>

<style>
  .tab-control {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    height: 40px;
    line-height: 40px;
    background-color: white;
    z-index: 9;
  }

  .tab-control-item {
    flex: 1;
    text-align: center;
  }

  .active span {
    color: var(--color-high-text);
    border-bottom: 3px solid var(--color-high-text);
  }
</style>
